home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-12-13 | 9.4 KB | 343 lines | [TEXT/MPS ] |
- /*
- File: TextEditorTransferExt.cpp
-
- Contains: Text Transfer Extension for TextEditor part.
-
- Written by: Troy Gaul
-
- Copyright: © 1995 by Apple Computer, Inc., all rights reserved.
-
- Issues: Additional methods that may be needed include:
- - InsertText
- - ReplaceSelection
-
- Both of the above methods may have the implementation in the data-transfer
- extension, e.g. no call to the owner part to do the above, just a GetPartData
- call, followed by inserting or replacing text in the local copy, and then a
- SetPartData call to the owner part. Or, the above calls can be made similar to
- GetData and SetData, just handling of the ODByteArray packaging. The first
- alternative is prob. the best, since it would be easy to rip out the code and
- replace it with the proper calls to the owner part.
- */
-
- // Notification that this is a SOM source file
- #define TextEditorTransferExt_Class_Source
-
- // define underscore field names (e.g. _fSelf)
- #define VARIABLE_MACROS
-
-
- #ifndef _COMPILERDEFS_
- #include "CompDefs.h"
- #endif
-
- // -- OpenDoc Utilities --
-
- #ifndef _EXCEPT_
- // Exceptions define several important macros (e.g. CHECKENV)
- // which are used in the SOM method dispatch glue. If Except.h
- // is not included early enough, exceptions may not be thrown
- // correctly when returning from a SOM method with "ev" parameter set.
- #include <Except.h>
- #endif
-
- // -- TextEditorTransferExt Includes --
-
- #ifndef SOM_TextEditorTransferExt_xih
- #include "TextEditorTransferExt.xih"
- #endif
-
- // -- TextEditor Includes --
-
- #ifndef SOM_SampleCode_TextEditor_xh
- #include "TextEditor.xh"
- #endif
-
- // -- OpenDoc Includes --
-
- #ifndef _ODTYPES_
- #include <ODTypes.h>
- #endif
-
- #ifndef SOM_ODExtension_xh
- #include <Extensn.xh>
- #endif
-
- #ifndef SOM_ODPlatformTypeList_xh
- #include <PfTypLs.xh>
- #endif
-
- #ifndef SOM_ODPlatformTypeListIterator_xh
- #include <PfTLItr.xh>
- #endif
-
- // -- OpenDoc Utilities --
-
- #ifndef _TEMPITER_
- #include <TempIter.h>
- #endif
-
- #ifndef _TEMPOBJ_
- #include <TempObj.h>
- #endif
-
- #ifndef _ODDEBUG_
- #include <ODDebug.h>
- #endif
-
- #ifndef _ODMEMORY_
- #include <ODMemory.h>
- #endif
-
- #ifndef _BARRAY_
- #include <BArray.h>
- #endif
-
- #ifndef _ODUTILS_
- #include <ODUtils.h>
- #endif
-
- #pragma segment somTextEditorTransferExt
-
- //==============================================================================
- // TextEditorTransferExt
- //==============================================================================
-
- //------------------------------------------------------------------------------
- // Method: somInit
- // Origin: SOMObject
- //
- // Description: This is the SOM equivalent of a C++ class constructor.
- //
- // Warnings: You are not allowed to throw an exception from this method.
- //------------------------------------------------------------------------------
- SOM_Scope void
- SOMLINK TextEditorTransferExt__somInit
- (
- TextEditorTransferExt *somSelf
- )
- {
- // TextEditorTransferExtData *somThis = TextEditorTransferExtGetData(somSelf);
- TextEditorTransferExtMethodDebug("TextEditorTransferExt","somInit");
-
- // somInit and somUninit methods behave like C++ constructors in that the
- // inherited methods are called automatically.
- // Thus, there is no need to call the parent class' somInit or somUninit.
-
- // There is also no need to set instance variables to zero/NULL
- // since SOM guarantees that a newly constructed object is zeroed.
- }
-
- //------------------------------------------------------------------------------
- // Method: somUninit
- // Origin: SOMObject
- //
- // Description: This is the SOM equivalent of a C++ class destructor.
- //
- // Warnings: You are not allowed to throw an exception from this method.
- //------------------------------------------------------------------------------
- SOM_Scope void
- SOMLINK TextEditorTransferExt__somUninit
- (
- TextEditorTransferExt *somSelf
- )
- {
- // TextEditorTransferExtData *somThis = TextEditorTransferExtGetData(somSelf);
- TextEditorTransferExtMethodDebug("TextEditorTransferExt","somUninit");
- }
-
- //------------------------------------------------------------------------------
- // Method: Release
- // Origin: ODRefCntObj
- //------------------------------------------------------------------------------
- SOM_Scope void
- SOMLINK TextEditorTransferExt__Release
- (
- TextEditorTransferExt* somSelf,
- Environment* ev
- )
- {
- // TextEditorTransferExtData *somThis = TextEditorTransferExtGetData(somSelf);
- TextEditorTransferExtMethodDebug("TextEditorTransferExt","Release");
-
- TextEditorTransferExt_parent_TextTransferExt_Release(somSelf,ev);
- }
-
- //------------------------------------------------------------------------------
- // Method: InitTextEditorTransferExt
- // Origin: TextEditorTransferExt
- //------------------------------------------------------------------------------
- SOM_Scope void
- SOMLINK TextEditorTransferExt__InitTextEditorTransferExt
- (
- TextEditorTransferExt* somSelf,
- Environment* ev,
- ODPart* owner
- )
- {
- TextEditorTransferExtData *somThis = TextEditorTransferExtGetData(somSelf);
- TextEditorTransferExtMethodDebug("TextEditorTransferExt","InitTextEditorTransferExt");
-
- SOM_TRY
- somSelf->InitTextTransferExt(ev, owner);
-
- _fOwner = (SampleCode_TextEditor*) owner->GetRealPart(ev);
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // Method: GetData
- // Origin: DataTransferExt
- //
- // Description: Called by client part to obtain data from the extensions owner.
- // Returns the first type of data from the ODTypeList which the owner
- // supports by creating an ODByteArray, storing the data with the above
- // header and then returning a pointer to the ODByteArray (or null)
- //------------------------------------------------------------------------------
- SOM_Scope ODBoolean
- SOMLINK TextEditorTransferExt__GetData
- (
- TextEditorTransferExt* somSelf,
- Environment* ev,
- ODPlatformType type,
- ODByteArray* data
- )
- {
- TextEditorTransferExtData *somThis = TextEditorTransferExtGetData(somSelf);
- TextEditorTransferExtMethodDebug("TextEditorTransferExt","GetData");
-
- ODBoolean supportsType = kODFalse;
-
- SOM_TRY
-
- // Note: TextEditor owns the block that is returned. Do not dispose
- // of this pointer.
-
- ODPtr thePtr = kODNULL;
- ODULong theSize = 0;
- supportsType = _fOwner->GetText(ev, type, &thePtr, &theSize);
-
- // If GetText returned a valid pointer, then repackage the
- // data into a ODByteArray.
- if ( thePtr != kODNULL )
- {
- data->_buffer = (octet*) ODNewPtrClear(theSize);
- ODBlockMove(thePtr, data->_buffer, theSize);
-
- data->_length = data->_maximum = theSize;
- }
-
- SOM_CATCH_ALL
- SOM_ENDTRY
-
- return supportsType;
- }
-
- //------------------------------------------------------------------------------
- // Method: SetData
- // Origin: DataTransferExt
- //
- // Description: Sets the data of the owner part to the data passed in the
- // ODByteArray.
- //------------------------------------------------------------------------------
-
- SOM_Scope ODBoolean
- SOMLINK TextEditorTransferExt__SetData
- (
- TextEditorTransferExt* somSelf,
- Environment* ev,
- ODPlatformType type,
- ODByteArray* data
- )
- {
- TextEditorTransferExtData *somThis = TextEditorTransferExtGetData(somSelf);
- TextEditorTransferExtMethodDebug("TextEditorTransferExt","SetData");
-
- ODBoolean supportsType = kODFalse;
-
- SOM_TRY
-
- supportsType = _fOwner->SetText(ev, type, data->_buffer, data->_length);
-
- SOM_CATCH_ALL
- SOM_ENDTRY
-
- return supportsType;
- }
-
- //------------------------------------------------------------------------------
- // Method: GetSelection
- // Origin: TextTransferExt
- //
- // Description: This method needs to be customized for the specific owner part.
- //------------------------------------------------------------------------------
-
- SOM_Scope ODBoolean
- SOMLINK TextEditorTransferExt__GetSelection
- (
- TextEditorTransferExt* somSelf,
- Environment* ev,
- ODULong* start,
- ODULong* end
- )
- {
- // TextEditorTransferExtData *somThis = TextEditorTransferExtGetData(somSelf);
- TextEditorTransferExtMethodDebug("TextEditorTransferExt","GetSelection");
-
- ODBoolean result = kODFalse;
-
- SOM_TRY
-
- // Needs to be customized to call the appropriate method of the owner part,
- // and then return the start and ending points of the selection.
- WARN("TextEditorTransferExt::GetSelection unimplemented");
-
- // Return true of false depending on the success of the operation.
- result = kODTrue;
-
- SOM_CATCH_ALL
- result = kODFalse;
- SOM_ENDTRY
-
- return result;
- }
-
- //------------------------------------------------------------------------------
- // Method: SetSelection
- // Origin: TextTransferExt
- //
- // Description: This method needs to be customized for the specific owner part.
- //------------------------------------------------------------------------------
-
- SOM_Scope ODBoolean
- SOMLINK TextEditorTransferExt__SetSelection
- (
- TextEditorTransferExt* somSelf,
- Environment* ev,
- ODULong start,
- ODULong end
- )
- {
- // TextEditorTransferExtData *somThis = TextEditorTransferExtGetData(somSelf);
- TextEditorTransferExtMethodDebug("TextEditorTransferExt","SetSelection");
-
- ODBoolean result = kODFalse;
-
- SOM_TRY
-
- // Needs to be customized to call the appropriate method of the owner part,
- // and then set the start and ending points of the selection.
- WARN("TextEditorTransferExt::SetSelection unimplemented");
-
- // Return true of false depending on the success of the operation.
- result = kODTrue;
-
- SOM_CATCH_ALL
- result = kODFalse;
- SOM_ENDTRY
-
- return result;
- }
-
-